<!DOCTYPE html>
<html lang="en" xmlns:th="http:www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>待生产管理</title>
    <link rel="stylesheet" href="/js/elementui/index.css">
    <script src="/js/vue/vue.js"></script>
    <script src="/js/axios/axios.min.js"></script>
    <script src="/js/qs/qs.min.js"></script>
    <script src="/js/elementui/index.js"></script>
</head>
<body>
<div id="app">
    <el-form ref="form" :model="form" label-width="150px">
        <el-form-item label="查询待生产订单">
            <el-input v-model="form.orderId" size="150px"  placeholder="请输入订单编号" clearable></el-input>
        </el-form-item>
        <el-form-item label="生产状态" :label-width="formLabelWidth">
            <template>
                <el-select v-model="form.productStatus" placeholder="请选择">
                    <el-option
                            v-for="item in productStatus2"
                            :label="item.productStatus1"
                            :value="item.productStatus">
                    </el-option>
                </el-select>
            </template>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>

        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    label="订单id"
                            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.id }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="订单编号"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.orderId }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="产品名称"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.orderType }}</span>
                </template>
            </el-table-column>
            <!--<el-table-column
                    label="产品型号"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.explains }}</span>
                </template>
            </el-table-column>-->
            <el-table-column
                    label="生产产线"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.operator }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="使用打印机"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.printer }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="生产时间"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.productTime }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="生产状态"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.productStatus1 }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="备注"
            >
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row.remark }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope" >
                    <el-button v-if="scope.row.laserCode == 1"
                            size="mini"
                            disabled
                            @click="handleEdit(scope.$index, scope.row)">加入到激光码生成列表</el-button>
                    <el-button v-else
                            size="mini"
                            @click="handleEdit(scope.$index, scope.row)">加入到激光码生成列表</el-button>
                </template>
            </el-table-column>
        </el-table>

    <!--分页-->
    <!--<el-pagination
            background
            layout="prev, pager, next"
            @current-change="loadPage"
            :total="total"
            :current-page="current"
            :page-size="pageSize">
    </el-pagination>-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="current"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>


    <!--添加-->
    <el-dialog title="设置生产记录" :visible.sync="dialogFormVisible" @close="closeMyDialog">
        <el-form :model="order">
            <el-form-item label="生产产线" :label-width="formLabelWidth">
                <template>
                    <el-select v-model="order.operator" placeholder="请选择">
                        <el-option
                                v-for="item in productLines"
                                :label="item.productionName"
                                :value="item.companyId">
                        </el-option>
                    </el-select>
                </template>
            </el-form-item>
            <!--<el-form-item label="打印机" :label-width="formLabelWidth">
                <template>
                    <el-select v-model="order.printer" placeholder="请选择">
                        <el-option
                                v-for="item in options"
                                :label="item.printer"
                                :value="item.printer">
                        </el-option>
                    </el-select>
                </template>
            </el-form-item>-->
        </el-form>
        <div class="block">
            <span class="demonstration">生产时间</span>
            <el-date-picker
                    v-model="order.productTime"
                    type="date"
                    placeholder="选择日期">
            </el-date-picker>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="saveProduct">确 定</el-button>
        </div>
    </el-dialog>

</div>
</body>
<script>
    new Vue({
        el:"#app",
        data() {
            return {
                tableData:null,
                current:1,
                total:0,
                options:null,
                productLines:null,
                productStatus2:null,
                dialogFormVisible:false,
                pageSize:5,
                order:{
                    id:"",
                    orderId:"",
                    printer:"",
                    companyId:"",
                    productionName:"",
                    laserCode:""
                },
                form:{
                    orderId:"",
                    productStatus:"",
                    productStatus1:"",
                    pageSize:"",
                    current:""
                }
            }
        },
        methods: {
            onSubmit() {
                /*axios.post("/selectOrderByIds",this.form).then(value => {
                    if(value.data.code==1){
                        this.tableData=value.data.data
                    }
                })*/
                this.pageSize=5
                this.total=0
                this.current=1
                this.loadPage(1,5)
            },
            handleEdit(index, row) {
                console.log(index, row);
                this.order=row
                this.dialogFormVisible =true
            },
            handleSizeChange(pageSize) {
                //console.log(`每页 ${val} 条`);
                this.loadPage(this.current,pageSize)
            },
            handleCurrentChange(current) {
                //console.log(`当前页: ${val}`);
                this.loadPage(current,this.pageSize)
            },
            //关闭对话框
            closeMyDialog(){
                //清空数据
                this.order = {      //产品对话框的数据
                    id:"",
                    printer:"",
                    companyId:"",
                    productionName:""
                }
            },
            saveProduct(){
                this.order. printer="";
                axios.put("/sc_dsc",this.order).then(value => {
                    if(value.data.code==1){
                        this.loadPage(this.current,this.pageSize)
                    }
                })
                this.dialogFormVisible =false
                if(confirm("加入成功是否跳到该页面")){
                    location.href='/productionLine/jgm.html'
                }
            },
            loadPage(current,pageSize){
                this.current=current
                this.pageSize=pageSize
                if(this.form.orderId==""){
                    axios.get("/sc_dsc?current="+current+"&pageSize="+pageSize).then(value => {
                        if(value.data.code==1){
                            this.tableData=value.data.data.records
                            this.total = value.data.data.total
                            this.pageSize = value.data.data.size
                            this.current = value.data.data.current
                        }

                    })
                }else {
                    this.form.current=current
                    this.form.pageSize=pageSize
                    axios.post("/selectOrderByIds",this.form).then(value => {
                        if(value.data.code==1){
                            this.tableData=value.data.data.records
                            this.total = value.data.data.total
                            this.pageSize = value.data.data.size
                            this.current = value.data.data.current
                        }
                    })
                }
            }
        },
        mounted(){
            this.loadPage(1,5)
            axios.get("/printer").then(value => {
                if(value.data.code==1){
                    this.options=value.data.data
                }
            }),
            axios.get("/productLine").then(value => {
                if(value.data.code==1){
                     this.productLines=value.data.data
                }
            })
            axios.get("/sc_dscOrderStatus").then(value => {
                if(value.data.code==1){
                    this.productStatus2=value.data.data
                }
            })

        }
    })
</script>
</html>